package com.czxy.demo01;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test17 {
    public static void main(String[] args) {
        Student s1=new Student("zhangsan",18,"男");
        Student s2=new Student("lihong",22,"女");
        Student s3=new Student("wangwu",19,"男");
        Student s4=new Student("wuwu",8,"女");
        Student s5=new Student("lilin",35,"男");

        List<Student> list=new ArrayList<Student>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.add(s5);

        getSex(list);


        int count1 = 0;
        int count2 = 0;

        for (Student student : list) {
            if(student.getAge()>18){
                count1++;
            }else {
                count2++;
            }
        }

        System.out.println("超过18岁的人有"+count1);
        System.out.println("没有超过18岁的人有"+count2);


    }
    public static void getSex(List<Student> list){
        Map<String,Integer> map = new HashMap<>();

        for (Student student : list) {
            String sex = student.getSex();
            Integer count = map.get(sex);
            if(count==null){
                count=1;
            }else {
                count++;
            }
            map.put(sex,count);
        }

        for (String s : map.keySet()) {
            System.out.println(s+" : "+map.get(s));
        }
    }
}
